using System;
using System.Collections.Generic;
using UnityEngine;

public class MenuPlayerprefs : MonoBehaviour
{
	public static bool IsDiamondADReward = true;

	public static int DiamondAdTimes;

	public static MenuPlayerprefs instance;

	[HideInInspector]
	public int StartPlane;

	[HideInInspector]
	public int allmoney;

	[HideInInspector]
	public int alldiamond;

	[HideInInspector]
	public int allenergy;

	[HideInInspector]
	public int allexp;

	[HideInInspector]
	public int maxenergy;

	[HideInInspector]
	public string EnergyStartTime;

	[HideInInspector]
	public int energylimittimes;

	[HideInInspector]
	public int curgamelevel;

	[HideInInspector]
	public int nextlevel;

	public int[] biglevelinfo;

	public int[] levelstar;

	public int[] levelboxinfo;

	public DateSave_Challenge[] DS_Challenge;

	public DataSave_Plane[] DS_Plane;

	public weaponlock[] armourlock;

	public weaponlock[] gunlock;

	public weaponlock[] longlock;

	public weaponlock[] multiplelock;

	public weaponlock[] misslock;

	public int[] piecenum;

	public int[] ds_star_achi;

	public int[] ds_item_achi;

	public int[] daytask_item;

	[HideInInspector]
	public int haveboxnum;

	[HideInInspector]
	public int allopenboxnum;

	public int[] pieceflag;

	private int[] playerExp = new int[18]
	{
		160,
		307,
		1010,
		1502,
		1983,
		3866,
		4892,
		5882,
		6837,
		10549,
		15364,
		13926,
		15291,
		16573,
		22399,
		19154,
		20167,
		21095
	};

	private string[] rankname = new string[19]
	{
		"列兵",
		"二等兵",
		"一等兵",
		"上等兵",
		"中士",
		"上士",
		"三级军士长",
		"一级军士长",
		"少尉",
		"中尉",
		"上尉",
		"少校",
		"中校",
		"上校",
		"准将",
		"少将",
		"中将",
		"上将",
		"五星上将"
	};

	public string[] ranknameImage = new string[19]
	{
		"Airman Basic",
		"Airman",
		"Airman First Class",
		"Senior Airman",
		"Staff Sergeant",
		"Technical Sergeant",
		"Master Sergeant",
		"Chief Master Sergeant",
		"Second Lieutenant",
		"First Lieutenant",
		"Captain",
		"Major",
		"Lieutenant Colonel",
		"Colonel",
		"Brigadier General",
		"Major General",
		"Lieutenant General",
		"General",
		"General of the Air Force"
	};

	[HideInInspector]
	public int firstshowgame;

	public int[] challengehint;

	public int[] planehint;

	[HideInInspector]
	public int menufirst;

	[HideInInspector]
	public int bonusisfirst;

	[HideInInspector]
	public int saleid;

	[HideInInspector]
	public int popsaleflag;

	[HideInInspector]
	public string SaleStartTime;

	private bool basedataflag;

	private bool chahintflag;

	private bool boxflag;

	private bool dailyflag;

	private int[] finishNum = new int[7]
	{
		6,
		3,
		2,
		3,
		1,
		20,
		600
	};

	private bool achiflag;

	private bool storeflag;

	private bool challgengeflag;

	private bool alllevelflag;

	private bool islostfocus;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
		biglevelinfo = new int[8];
		levelstar = new int[48];
		levelboxinfo = new int[16];
		DS_Challenge = new DateSave_Challenge[4];
		DS_Plane = new DataSave_Plane[10];
		armourlock = new weaponlock[8];
		gunlock = new weaponlock[10];
		longlock = new weaponlock[8];
		multiplelock = new weaponlock[8];
		misslock = new weaponlock[2];
		piecenum = new int[10];
		ds_star_achi = new int[18];
		ds_item_achi = new int[18];
		daytask_item = new int[7];
		pieceflag = new int[10];
		challengehint = new int[12];
		planehint = new int[10];
	}

	public void readstartplane()
	{
		StartPlane = PlayerPrefs.GetInt("startplane");
	}

	public void savestartplane(int startnum)
	{
		if (StartPlane != startnum)
		{
			StartPlane = startnum;
			PlayerPrefs.SetInt("startplane", startnum);
		}
	}

	public void readBaseData()
	{
		if (!basedataflag)
		{
			basedataflag = true;
			allmoney = PlayerPrefs.GetInt("coin", 200);
			alldiamond = PlayerPrefs.GetInt("diamond", 20);
			allenergy = PlayerPrefs.GetInt("energy", 30);
			allexp = PlayerPrefs.GetInt("exp", 0);
			maxenergy = PlayerPrefs.GetInt("maxenergy", 30);
			EnergyStartTime = PlayerPrefs.GetString("energystarttime", "1");
			energylimittimes = PlayerPrefs.GetInt("energylimittimes", 0);
			firstshowgame = PlayerPrefs.GetInt("firstshowgame", 0);
			menufirst = PlayerPrefs.GetInt("menufirst", 1);
			bonusisfirst = PlayerPrefs.GetInt("bonusfirst", 1);
			saleid = PlayerPrefs.GetInt("saleid", 0);
			SaleStartTime = PlayerPrefs.GetString("salestarttime", "1");
			popsaleflag = PlayerPrefs.GetInt("popsaleflag", 0);
			curgamelevel = PlayerPrefs.GetInt("curlevel", 0);
			string str = DateTime.Now.ToShortDateString();
			if (PlayerPrefs.GetInt("AdTimes" + str, 0) == 0)
			{
				PlayerPrefs.SetInt("DiamondAdTimes", 0);
				DiamondAdTimes = 0;
				PlayerPrefs.SetInt("AdTimes" + str, 1);
			}
			else
			{
				DiamondAdTimes = PlayerPrefs.GetInt("DiamondAdTimes", 0);
			}
			if (DiamondAdTimes > 6)
			{
				IsDiamondADReward = false;
			}
			else
			{
				IsDiamondADReward = true;
			}
		}
	}

	public static void SaveAdTimes()
	{
		DiamondAdTimes++;
		PlayerPrefs.SetInt("DiamondAdTimes", DiamondAdTimes);
		if (DiamondAdTimes >= 6)
		{
			IsDiamondADReward = false;
		}
		else
		{
			IsDiamondADReward = true;
		}
	}

	public void setmenufirst()
	{
		menufirst = 0;
		PlayerPrefs.SetInt("menufirst", 0);
	}

	public void setbonusfirst(int num)
	{
		bonusisfirst = num;
		PlayerPrefs.SetInt("bonusfirst", num);
	}

	public void save_sale(int id)
	{
		saleid = id;
		SaleStartTime = DateTime.Now.Ticks.ToString();
		PlayerPrefs.SetInt("saleid", saleid);
		PlayerPrefs.SetString("salestarttime", SaleStartTime);
	}

	public void set_popsaleflag()
	{
		popsaleflag = 0;
		PlayerPrefs.SetInt("popsaleflag", 0);
	}

	public void ForSaleGive(int id)
	{
		if (id == 12)
		{
			unlock_armour(1);
			unlock_long(1);
			AddEnergy(60);
			AddMoney(6000);
			AddDiamod(130);
			save_plane_lock(2);
			if (curgamelevel >= 17)
			{
				save_sale(2);
			}
			else
			{
				save_sale(1);
			}
		}
		else
		{
			unlock_armour(4);
			unlock_gun(4);
			unlock_long(3);
			unlock_multiple(3);
			unlock_miss(0);
			save_plane_lock(5);
			save_sale(3);
		}
		PlayerPrefs.Save();
		MenuUIController.instance.mainui.sale_buyok(id);
		MenuUIController.instance.mainui.changePlane();
	}

	public void readchall_hint()
	{
		if (!chahintflag)
		{
			chahintflag = true;
			for (int i = 0; i < challengehint.Length; i++)
			{
				challengehint[i] = PlayerPrefs.GetInt("chalhint" + i, 0);
			}
		}
	}

	public void setchall_hint(int index)
	{
		if (challengehint[index] != 1)
		{
			challengehint[index] = 1;
			PlayerPrefs.SetInt("chalhint" + index, 1);
		}
	}

	public void readbox()
	{
		if (!boxflag)
		{
			haveboxnum = PlayerPrefs.GetInt("haveboxnum", 0);
			allopenboxnum = PlayerPrefs.GetInt("allopenboxnum", 0);
			for (int i = 0; i < pieceflag.Length; i++)
			{
				pieceflag[i] = PlayerPrefs.GetInt("pieceflag" + i, 0);
			}
			boxflag = true;
		}
	}

	public void savebox(int num)
	{
		haveboxnum += num;
		if (haveboxnum <= 0)
		{
			haveboxnum = 0;
		}
		if (num != 0)
		{
			PlayerPrefs.SetInt("haveboxnum", haveboxnum);
		}
		if (num < 0)
		{
			allopenboxnum -= num;
			PlayerPrefs.SetInt("allopenboxnum", allopenboxnum);
		}
	}

	public void savepieceflag(int ind)
	{
		pieceflag[ind] = 1;
		PlayerPrefs.SetInt("pieceflag" + ind, 1);
	}

	public void readdailytask()
	{
		if (dailyflag)
		{
			return;
		}
		dailyflag = true;
		if (Platform.GetServerTime() > 0)
		{
			string str = DateTime.Now.ToShortDateString();
			if (PlayerPrefs.GetInt("daytasktime" + str, 0) == 0)
			{
				for (int i = 0; i < daytask_item.Length; i++)
				{
					daytask_item[i] = 0;
					PlayerPrefs.SetInt("daytask" + i, 0);
				}
				PlayerPrefs.SetInt("daytasktime" + str, 1);
			}
			else
			{
				for (int j = 0; j < daytask_item.Length; j++)
				{
					daytask_item[j] = PlayerPrefs.GetInt("daytask" + j, 0);
				}
			}
		}
		else
		{
			for (int k = 0; k < daytask_item.Length; k++)
			{
				daytask_item[k] = PlayerPrefs.GetInt("daytask" + k, 0);
			}
		}
	}

	public int readdaytask_zero()
	{
		daytask_item[0] = 0;
		for (int i = 1; i < daytask_item.Length - 1; i++)
		{
			if (daytask_item[i] == -1 || daytask_item[i] >= finishNum[i])
			{
				daytask_item[0]++;
			}
		}
		if (daytask_item[6] == -1 || daytask_item[6] + (int)Time.time >= finishNum[6])
		{
			daytask_item[0]++;
		}
		return daytask_item[0];
	}

	public void savedailytask(int index)
	{
		if (daytask_item[index] != -1)
		{
			daytask_item[index]++;
			PlayerPrefs.SetInt("daytask" + index, daytask_item[index]);
		}
	}

	public void setdailytask(int index, int num)
	{
		if (daytask_item[index] != num)
		{
			daytask_item[index] = num;
			PlayerPrefs.SetInt("daytask" + index, daytask_item[index]);
		}
	}

	public void adddailytask(int index, int num)
	{
		if (num != 0 && daytask_item[index] != -1)
		{
			daytask_item[index] += num;
			PlayerPrefs.SetInt("daytask" + index, daytask_item[index]);
		}
	}

	public void readachievement()
	{
		if (!achiflag)
		{
			achiflag = true;
			for (int i = 0; i < ds_star_achi.Length; i++)
			{
				ds_star_achi[i] = PlayerPrefs.GetInt("star_achi" + i, 0);
				ds_item_achi[i] = PlayerPrefs.GetInt("item_achi" + i, 0);
			}
			if (ds_item_achi[2] == 0)
			{
				ds_item_achi[2] = 1;
			}
			if (ds_item_achi[3] == 0)
			{
				ds_item_achi[3] = 1;
			}
			if (ds_item_achi[4] == 0)
			{
				ds_item_achi[4] = 1;
			}
		}
	}

	public void savestarachi(int index)
	{
		ds_star_achi[index]++;
		PlayerPrefs.SetInt("star_achi" + index, ds_star_achi[index]);
		Platform.flurryEvent_achievement(index, ds_star_achi[index]);
	}

	public void saveitemachi(int index, int num)
	{
		ds_item_achi[index] += num;
		PlayerPrefs.SetInt("item_achi" + index, ds_item_achi[index]);
	}

	public void readpiece()
	{
		for (int i = 0; i < piecenum.Length; i++)
		{
			piecenum[i] = PlayerPrefs.GetInt("piecenum" + i, 0);
		}
	}

	public void addpiece(int index, int num)
	{
		if (num != 0)
		{
			piecenum[index] += num;
			PlayerPrefs.SetInt("piecenum" + index, piecenum[index]);
		}
	}

	public bool DecPiece(int index, int num)
	{
		if (piecenum[index] >= num)
		{
			piecenum[index] -= num;
			PlayerPrefs.SetInt("piecenum" + index, piecenum[index]);
			return true;
		}
		return false;
	}

	public void readStoreData()
	{
		if (storeflag)
		{
			return;
		}
		storeflag = true;
		for (int i = 0; i < DS_Plane.Length; i++)
		{
			if (i == 0)
			{
				DS_Plane[i].islock = PlayerPrefs.GetInt("planelock" + i, 0);
			}
			else
			{
				DS_Plane[i].islock = PlayerPrefs.GetInt("planelock" + i, 1);
			}
			DS_Plane[i].armourtype = PlayerPrefs.GetInt("armourtype" + i, 0);
			DS_Plane[i].guntype = PlayerPrefs.GetInt("guntype" + i, 0);
			DS_Plane[i].longtype = PlayerPrefs.GetInt("longtype" + i, 0);
			DS_Plane[i].multipletype = PlayerPrefs.GetInt("multipletype" + i, -1);
			DS_Plane[i].misstype = PlayerPrefs.GetInt("misstype" + i, -1);
		}
		for (int j = 0; j < armourlock.Length; j++)
		{
			if (j == 0)
			{
				armourlock[j].islock = PlayerPrefs.GetInt("armourlock" + j, 0);
			}
			else
			{
				armourlock[j].islock = PlayerPrefs.GetInt("armourlock" + j, 1);
			}
			armourlock[j].curlv = PlayerPrefs.GetInt("armourlockcurlv" + j, 0);
		}
		for (int k = 0; k < gunlock.Length; k++)
		{
			if (k == 0)
			{
				gunlock[k].islock = PlayerPrefs.GetInt("gunlock" + k, 0);
			}
			else
			{
				gunlock[k].islock = PlayerPrefs.GetInt("gunlock" + k, 1);
			}
			gunlock[k].curlv = PlayerPrefs.GetInt("gunlockcurlv" + k, 0);
		}
		for (int l = 0; l < longlock.Length; l++)
		{
			if (l == 0)
			{
				longlock[l].islock = PlayerPrefs.GetInt("longlock" + l, 0);
			}
			else
			{
				longlock[l].islock = PlayerPrefs.GetInt("longlock" + l, 1);
			}
			longlock[l].curlv = PlayerPrefs.GetInt("longlockcurlv" + l, 0);
		}
		for (int m = 0; m < multiplelock.Length; m++)
		{
			multiplelock[m].islock = PlayerPrefs.GetInt("multiplelock" + m, 1);
			multiplelock[m].curlv = PlayerPrefs.GetInt("multiplelockcurlv" + m, 0);
		}
		for (int n = 0; n < misslock.Length; n++)
		{
			misslock[n].islock = PlayerPrefs.GetInt("misslock" + n, 1);
			misslock[n].curlv = PlayerPrefs.GetInt("misslockcurlv" + n, 0);
		}
		for (int num = 0; num < planehint.Length; num++)
		{
			planehint[num] = PlayerPrefs.GetInt("planehint" + num, 1);
		}
		planehint[0] = 0;
	}

	public void set_planehint(int num)
	{
		if (planehint[num] == 1)
		{
			planehint[num] = 0;
			PlayerPrefs.SetInt("planehint" + num, 0);
		}
	}

	public bool getmultipleisunlock()
	{
		for (int i = 0; i < multiplelock.Length; i++)
		{
			if (multiplelock[i].islock == 0)
			{
				return true;
			}
		}
		return false;
	}

	public bool getmissisunlock()
	{
		for (int i = 0; i < misslock.Length; i++)
		{
			if (misslock[i].islock == 0)
			{
				return true;
			}
		}
		return false;
	}

	public void save_plane_lock(int index)
	{
		if (DS_Plane[index].islock != 0)
		{
			DS_Plane[index].islock = 0;
			PlayerPrefs.SetInt("planelock" + index, DS_Plane[index].islock);
			savestartplane(index);
			init_plane_weapon(index);
			saveitemachi(2, 1);
			Platform.flurryEvent_plane(index);
		}
	}

	public void init_plane_weapon(int planeid)
	{
		int level = MenuDataController.instance.PlaneData[planeid].level;
		int equipednum = -1;
		for (int i = 0; i < armourlock.Length; i++)
		{
			if (armourlock[i].islock == 0 && MenuDataController.instance.ArmourData[i].planelevel <= level)
			{
				equipednum = i;
			}
		}
		save_plane_armour(planeid, equipednum);
		equipednum = -1;
		for (int j = 0; j < gunlock.Length; j++)
		{
			if (gunlock[j].islock == 0 && MenuDataController.instance.MachineGunData[j].planelevel <= level)
			{
				equipednum = j;
			}
		}
		save_plane_gun(planeid, equipednum);
		equipednum = -1;
		for (int k = 0; k < longlock.Length; k++)
		{
			if (longlock[k].islock == 0 && MenuDataController.instance.longmissileData[k].planelevel <= level)
			{
				equipednum = k;
			}
		}
		save_plane_long(planeid, equipednum);
		equipednum = -1;
		for (int l = 0; l < multiplelock.Length; l++)
		{
			if (multiplelock[l].islock == 0 && MenuDataController.instance.MultipleData[l].planelevel <= level)
			{
				equipednum = l;
			}
		}
		save_plane_multiple(planeid, equipednum);
		equipednum = -1;
		for (int m = 0; m < misslock.Length; m++)
		{
			if (misslock[m].islock == 0 && MenuDataController.instance.YoudaodanData[m].planelevel <= level)
			{
				equipednum = m;
			}
		}
		save_plane_miss(planeid, equipednum);
	}

	public void save_plane_armour(int index, int equipednum)
	{
		if (DS_Plane[index].armourtype != equipednum)
		{
			DS_Plane[index].armourtype = equipednum;
			PlayerPrefs.SetInt("armourtype" + index, equipednum);
		}
	}

	public void save_plane_gun(int index, int equipednum)
	{
		if (DS_Plane[index].guntype != equipednum)
		{
			DS_Plane[index].guntype = equipednum;
			PlayerPrefs.SetInt("guntype" + index, equipednum);
		}
	}

	public void save_plane_long(int index, int equipednum)
	{
		if (DS_Plane[index].longtype != equipednum)
		{
			DS_Plane[index].longtype = equipednum;
			PlayerPrefs.SetInt("longtype" + index, equipednum);
		}
	}

	public void save_plane_multiple(int index, int equipednum)
	{
		if (DS_Plane[index].multipletype != equipednum)
		{
			DS_Plane[index].multipletype = equipednum;
			PlayerPrefs.SetInt("multipletype" + index, equipednum);
		}
	}

	public void save_plane_miss(int index, int equipednum)
	{
		if (DS_Plane[index].misstype != equipednum)
		{
			DS_Plane[index].misstype = equipednum;
			PlayerPrefs.SetInt("misstype" + index, equipednum);
		}
	}

	public void save_weapon_armour(int index, weaponlock wea)
	{
		if (armourlock[index].islock == 1)
		{
			Platform.flurryEvent_store(0, index, -1);
		}
		Platform.flurryEvent_store(0, index, wea.curlv);
		armourlock[index] = wea;
		PlayerPrefs.SetInt("armourlock" + index, wea.islock);
		PlayerPrefs.SetInt("armourlockcurlv" + index, wea.curlv);
	}

	public void unlock_armour(int index)
	{
		if (armourlock[index].islock != 0)
		{
			armourlock[index].islock = 0;
			PlayerPrefs.SetInt("armourlock" + index, 0);
			Platform.flurryEvent_store(0, index, -1);
		}
	}

	public void save_weapon_gun(int index, weaponlock wea)
	{
		if (gunlock[index].islock == 1)
		{
			Platform.flurryEvent_store(1, index, -1);
		}
		Platform.flurryEvent_store(1, index, wea.curlv);
		gunlock[index] = wea;
		PlayerPrefs.SetInt("gunlock" + index, wea.islock);
		PlayerPrefs.SetInt("gunlockcurlv" + index, wea.curlv);
	}

	public void unlock_gun(int index)
	{
		gunlock[index].islock = 0;
		PlayerPrefs.SetInt("gunlock" + index, 0);
		Platform.flurryEvent_store(1, index, -1);
	}

	public void save_weapon_long(int index, weaponlock wea)
	{
		if (longlock[index].islock == 1)
		{
			Platform.flurryEvent_store(2, index, -1);
		}
		Platform.flurryEvent_store(2, index, wea.curlv);
		longlock[index] = wea;
		PlayerPrefs.SetInt("longlock" + index, wea.islock);
		PlayerPrefs.SetInt("longlockcurlv" + index, wea.curlv);
	}

	public void unlock_long(int index)
	{
		if (longlock[index].islock != 0)
		{
			longlock[index].islock = 0;
			PlayerPrefs.SetInt("longlock" + index, 0);
			Platform.flurryEvent_store(2, index, -1);
		}
	}

	public void save_weapon_multiple(int index, weaponlock wea)
	{
		if (multiplelock[index].islock == 1)
		{
			Platform.flurryEvent_store(3, index, -1);
		}
		Platform.flurryEvent_store(3, index, wea.curlv);
		multiplelock[index] = wea;
		PlayerPrefs.SetInt("multiplelock" + index, wea.islock);
		PlayerPrefs.SetInt("multiplelockcurlv" + index, wea.curlv);
	}

	public void unlock_multiple(int index)
	{
		if (multiplelock[index].islock != 0)
		{
			multiplelock[index].islock = 0;
			PlayerPrefs.SetInt("multiplelock" + index, 0);
			Platform.flurryEvent_store(3, index, -1);
		}
	}

	public void save_multiple_bonus()
	{
		multiplelock[1].islock = 0;
		PlayerPrefs.SetInt("multiplelock" + 1, 0);
		Platform.flurryEvent_store(3, 1, -1);
	}

	public void save_weapon_miss(int index, weaponlock wea)
	{
		if (misslock[index].islock == 1)
		{
			Platform.flurryEvent_store(4, index, -1);
		}
		Platform.flurryEvent_store(4, index, wea.curlv);
		misslock[index] = wea;
		PlayerPrefs.SetInt("misslock" + index, wea.islock);
		PlayerPrefs.SetInt("misslockcurlv" + index, wea.curlv);
	}

	public void unlock_miss(int index)
	{
		if (misslock[index].islock != 0)
		{
			misslock[index].islock = 0;
			PlayerPrefs.SetInt("misslock" + index, 0);
			Platform.flurryEvent_store(4, index, -1);
		}
	}

	public void readChallenge()
	{
		if (!challgengeflag)
		{
			challgengeflag = true;
			for (int i = 0; i < 4; i++)
			{
				DS_Challenge[i].challengetime = PlayerPrefs.GetString("challengetime" + i);
				DS_Challenge[i].challengenum = PlayerPrefs.GetInt("challengenum" + i, 3);
			}
		}
	}

	public void saveChallenge(int num, DateSave_Challenge ds)
	{
		DS_Challenge[num] = ds;
		PlayerPrefs.SetString("challengetime" + num, DS_Challenge[num].challengetime);
		PlayerPrefs.SetInt("challengenum" + num, DS_Challenge[num].challengenum);
	}

	public void Addbox(int num)
	{
		readbox();
		haveboxnum += num;
		PlayerPrefs.SetInt("haveboxnum", haveboxnum);
	}

	public void AddMoney(int num, bool late = false)
	{
		allmoney += num;
		PlayerPrefs.SetInt("coin", allmoney);
		MenuUIController.instance.uplineui.infoUpdate(late);
	}

	public void AddDiamod(int num, bool late = false)
	{
		alldiamond += num;
		PlayerPrefs.SetInt("diamond", alldiamond);
		MenuUIController.instance.uplineui.infoUpdate(late);
	}

	public void AddEnergy(int num, bool late = false)
	{
		allenergy += num;
		PlayerPrefs.SetInt("energy", allenergy);
		MenuUIController.instance.uplineui.infoUpdate(late);
	}

	public bool recoverEnergy(int num)
	{
		if (num == 0)
		{
			return false;
		}
		allenergy += num;
		if (allenergy >= maxenergy)
		{
			allenergy = maxenergy;
			PlayerPrefs.SetInt("energy", allenergy);
			MenuUIController.instance.updateenergy();
			return true;
		}
		PlayerPrefs.SetInt("energy", allenergy);
		MenuUIController.instance.updateenergy();
		return false;
	}

	public void SetMaxenergy(int num, bool late = false)
	{
		if (allenergy >= maxenergy && allenergy < maxenergy + num)
		{
			EnergyStartTime = DateTime.Now.Ticks.ToString();
			PlayerPrefs.SetString("energystarttime", EnergyStartTime);
		}
		maxenergy += num;
		energylimittimes++;
		PlayerPrefs.SetInt("maxenergy", maxenergy);
		PlayerPrefs.SetInt("energylimittimes", energylimittimes);
		MenuUIController.instance.uplineui.infoUpdate(late);
	}

	public void SetEnergyStarttime(string time)
	{
		EnergyStartTime = time;
		PlayerPrefs.SetString("energystarttime", EnergyStartTime);
	}

	public bool DecMoney(int num)
	{
		if (allmoney >= num)
		{
			allmoney -= num;
			PlayerPrefs.SetInt("coin", allmoney);
			MenuUIController.instance.uplineui.infoUpdate();
			return true;
		}
		return false;
	}

	public bool DecDiamond(int num)
	{
		if (alldiamond >= num)
		{
			alldiamond -= num;
			PlayerPrefs.SetInt("diamond", alldiamond);
			MenuUIController.instance.uplineui.infoUpdate();
			return true;
		}
		return false;
	}

	public bool DecEnergy(int num)
	{
		if (allenergy >= num)
		{
			if (allenergy >= maxenergy && allenergy - num < maxenergy)
			{
				EnergyStartTime = DateTime.Now.Ticks.ToString();
				PlayerPrefs.SetString("energystarttime", EnergyStartTime);
			}
			allenergy -= num;
			PlayerPrefs.SetInt("energy", allenergy);
			MenuUIController.instance.uplineui.infoUpdate();
			return true;
		}
		return false;
	}

	public void readAllLevel()
	{
		if (!alllevelflag)
		{
			alllevelflag = true;
			curgamelevel = PlayerPrefs.GetInt("curlevel", 0);
			nextlevel = PlayerPrefs.GetInt("nextlevel", 0);
			for (int i = 0; i < biglevelinfo.Length; i++)
			{
				biglevelinfo[i] = PlayerPrefs.GetInt("biglevel" + i, 0);
			}
			for (int j = 0; j < levelstar.Length; j++)
			{
				levelstar[j] = PlayerPrefs.GetInt("levelstar" + j);
			}
			for (int k = 0; k < levelboxinfo.Length; k++)
			{
				levelboxinfo[k] = PlayerPrefs.GetInt("levelbox" + k);
			}
			if (biglevelinfo[0] / 1000000 == 0)
			{
				biglevelinfo[0] += 1000000;
				setlevel(0, biglevelinfo[0]);
			}
			if (biglevelinfo[curgamelevel / 6] / 1000000 == 0 && GetAllstar() >= MenuDataController.instance.levellockinfo[curgamelevel / 6].maxstar)
			{
				biglevelinfo[curgamelevel / 6] += 1000000;
				setlevel(curgamelevel / 6, biglevelinfo[curgamelevel / 6]);
			}
		}
	}

	public void setlevelbox(int index)
	{
		if (levelboxinfo[index] != 1)
		{
			levelboxinfo[index] = 1;
			PlayerPrefs.SetInt("levelbox" + index, 1);
		}
	}

	public void setlevel(int levelindex, int val)
	{
		biglevelinfo[levelindex] = val;
		PlayerPrefs.SetInt("biglevel" + levelindex, val);
	}

	public int GetAllstar()
	{
		int num = 0;
		for (int i = 0; i < biglevelinfo.Length; i++)
		{
			num += callevel_star(biglevelinfo[i]);
		}
		return num;
	}

	public void Setlevelunlock()
	{
		biglevelinfo[curgamelevel / 6] += 1000000;
		setlevel(curgamelevel / 6, biglevelinfo[curgamelevel / 6]);
	}

	public int getlevel_star(int lv_ind)
	{
		return callevel_star(biglevelinfo[lv_ind]);
	}

	public int callevel_star(int num)
	{
		num %= 1000000;
		if (num < 10)
		{
			return num;
		}
		int num2 = 0;
		while (num > 0)
		{
			num2 += num % 10;
			num /= 10;
		}
		return num2;
	}

	public expdata GetExp()
	{
		int num = allexp;
		expdata result = default(expdata);
		result.allexp = num;
		result.level = 0;
		int num2 = 0;
		for (int i = 0; i < 18; i++)
		{
			if (num - playerExp[i] >= 0)
			{
				num -= playerExp[i];
				num2 = i + 1;
			}
		}
		result.level = num2 + 1;
		result.name = rankname[num2];
		result.curexp = num;
		if (num2 >= 18)
		{
			result.maxexp = 0;
			result.nextname = null;
		}
		else
		{
			result.maxexp = playerExp[num2];
			result.nextname = rankname[num2 + 1];
		}
		return result;
	}

	public void SetExp()
	{
		int num = allexp;
		int num2 = 0;
		for (int i = 0; i < 18; i++)
		{
			if (num - playerExp[i] >= 0)
			{
				num -= playerExp[i];
				num2 = i + 1;
			}
		}
		num = 0;
		if (num2 >= 18)
		{
			num2 = 18;
		}
		for (int j = 0; j < num2 + 1; j++)
		{
			num += playerExp[j];
		}
		num = (allexp = num + 1);
		PlayerPrefs.SetInt("exp", allexp);
	}

	public string getplayername(int nameindex)
	{
		return ranknameImage[nameindex];
	}
	public string getplayernameCN(int nameindex)
	{
		return rankname[nameindex];
	}

	public List<int> GetUnlockPlane()
	{
		List<int> list = new List<int>();
		for (int i = 0; i < DS_Plane.Length; i++)
		{
			if (DS_Plane[i].islock == 0)
			{
				list.Add(i);
			}
		}
		return list;
	}

	public float GetEnergyrota()
	{
		return (float)allenergy / (float)maxenergy;
	}

	public void DelAll()
	{
		PlayerPrefs.DeleteAll();
	}

	public int GetDelEnergy()
	{
		return maxenergy - allenergy;
	}

	public void Setfirstmoregame()
	{
		firstshowgame = 1;
		PlayerPrefs.SetInt("firstshowgame", 1);
	}

	public int getlevel_first(int lv)
	{
		return PlayerPrefs.GetInt("levelfirst_start" + lv, 1);
	}

	public void SetLevel_first(int lv)
	{
		PlayerPrefs.SetInt("levelfirst_start" + lv, 0);
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}

	private void OnApplicationQuit()
	{
		adddailytask(6, (int)Time.time);
		int delEnergy = GetDelEnergy();
		if (DateTime.Now.Hour < 19)
		{
			if ((19 - DateTime.Now.Hour) * 60 * 60 - DateTime.Now.Minute * 60 - DateTime.Now.Second >= delEnergy * 300 && delEnergy > 0)
			{
				Platform.setNotification(0, 1, 0L, Platform.notification[1]);
			}
			else
			{
				Platform.setNotification(0, 1, 0L, Platform.notification[0]);
			}
		}
		Platform.setNotification(1, 1, 0L, Platform.notification[2]);
		Platform.setNotification(2, 1, 0L, Platform.notification[2]);
		Platform.setNotification(3, 1, 0L, Platform.notification[1]);
		Platform.setNotification(4, 1, 0L, Platform.notification[3]);
		Platform.setNotification(5, 1, 0L, Platform.notification[3]);
		Platform.setNotification(6, 1, 0L, Platform.notification[3]);
	}

	private void OnApplicationFocus(bool isfocus)
	{
		if (isfocus)
		{
			if (islostfocus)
			{
				Platform.cancleAllNotification();
			}
			return;
		}
		islostfocus = true;
		PlayerPrefs.Save();
		int delEnergy = GetDelEnergy();
		if (DateTime.Now.Hour < 19)
		{
			if ((19 - DateTime.Now.Hour) * 60 * 60 - DateTime.Now.Minute * 60 - DateTime.Now.Second >= delEnergy * 300 && delEnergy > 0)
			{
				Platform.setNotification(0, 1, 0L, Platform.notification[1]);
			}
			else
			{
				Platform.setNotification(0, 1, 0L, Platform.notification[0]);
			}
		}
		Platform.setNotification(1, 1, 0L, Platform.notification[2]);
		Platform.setNotification(2, 1, 0L, Platform.notification[2]);
		Platform.setNotification(3, 1, 0L, Platform.notification[1]);
		Platform.setNotification(4, 1, 0L, Platform.notification[3]);
		Platform.setNotification(5, 1, 0L, Platform.notification[3]);
		Platform.setNotification(6, 1, 0L, Platform.notification[3]);
	}
}
